#define _GNU_SOURCE
#include <assert.h>
#include <stdlib.h>
#include <libapfsds.h>
#include <ddblk_plat.h>
#include <dbg.h>
#include <dbg/ptest.h>
#include <pthreadalt.h>
#include <add.h>

static TLS_INITIAL tid_t mytid;

#define TEST_NR		(100000000)
#define TEST_LOCKS	(1)
#define TEST_THREADNR	(HDEF_NATIVE_CPU_NR)
word_t test_nrs_arr[] = {1, HDEF_NATIVE_CPU_NR};
#define WARMUP_THREAD_NR	16
addcount_t addcnt;
static void *tadd(void *args){
	word_t ret = 0;
	for (;;)
	{
		ret = faa(&addcnt.val, 1);
		if(ret >= TEST_NR) break;
	}
	return NULL;
}
__PERF_PARALLEL_FUNC_BINDCORE_CUSTOM(tadd , mytid, TEST_NR, TEST_THREADNR, HDEF_LITTLECORE_OFFST, assert(addcnt.val >= TEST_NR); addcnt.val = 0, test_nrs_arr, dbg_printf)

int main(){
	count_init(&addcnt);
	addcnt.val = TEST_NR;
	PERF_PARALLEL_RUN(tadd);
	return 0;
}